<?php


/**
* json字符串以双引号包含
* 连续且是0开头的索引数组，才能转换为json数组
* 要编码的数组的键不是从0开始的数字，所有的键将会被当作字符串，并明确声明为 key-value 对。非连续且不是0开头的索引数组，转化为json时，key会转化为字符串
* 非连续且不是0开头的索引数组，转化为json时，key会转化为字符串
* 非连续且不是0开头的数组，都会被转换为对象，非连续且不是0开头的数组变量，为空时，会转换为数组
*
 * JSON_UNESCAPED_UNICODE 使用多子节unicode编码，支持中文
 * JSON_PRETTY_PRINT 使用空格格式化json，就不需要使用开发者工具解析，配合header头
* 
**/

/**
 * 1.需要解决的是空数组json后是[],变量非空的是json可能是空对象
 *
 */
$arr = [null, true,false, 0,'0.1', 'abc'];
var_dump(json_encode($arr, JSON_PRETTY_PRINT));


$arr= [];
$url = 'http://www.domain.com/#id/1';
$arr['null'] = json_encode(null);
$arr['true'] = json_encode(true);
$arr['int'] = json_encode(124);
$arr['float'] = json_encode(124.01);
$arr['string'] = json_encode('abcdefg');
$arr['url'] = json_encode($url);
$arr['url 不编码/'] = json_encode($url, JSON_UNESCAPED_SLASHES);
$arr['url encode2次'] = json_encode($arr['url']);
$arr['arr[]'] = json_encode([]);
$arr['arr[1,2,3]'] = json_encode([1,2,3]);
$arr['arr[0 => 1,2 =>2, 3 => 3]'] = json_encode([0 => 1,2 =>2, 3 => 3]);
$arr['arr[1=> 1,2 => 2,3 =>3]'] = json_encode([1=> 1,2 => 2,3 =>3]);
$arr['arr[a=> 1,b => 2,c =>3]'] = json_encode(['a'=> 1, 'b' => 2,'c' =>3]);
$arr['null oject'] = json_encode((object)[]);
$arr['stdClass oject'] = json_encode(new stdClass());

$arr['string:你好'] = json_encode('你好');
$arr['string:你好:JSON_UNESCAPED_UNICODE'] = json_encode('你好', JSON_UNESCAPED_UNICODE);  //显示中文
$arr['JSON_PRETTY_PRINT'] = json_encode(['a'=> 1, 'b' => 2,'c' =>3], JSON_PRETTY_PRINT);


var_dump($arr);


$arr1 =  [
    "build_id"    => "33010901",
    "destroy"     => 1,
    "destroy_num" => 2,
    "info" =>  [],
    "name"        => "charm_statue",
    "step"        => 6,
    13,
];

$arr1 = json_encode($arr1);
var_dump($arr1);